package com.mingmen.supplier.activity;


import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.mingmen.supplier.R;
import com.mingmen.supplier.adapter.CanCelOrderAdapter;
import com.mingmen.supplier.adapter.CommodityAdapter;
import com.mingmen.supplier.adapter.MyCommentAdapter;
import com.mingmen.supplier.adapter.MyPagerAdapter;
import com.mingmen.supplier.adapter.PhotoWaiAdapter;
import com.mingmen.supplier.immersionbar.ImmersionBar;
import com.mingmen.supplier.model.MySimpleData;
import com.mingmen.supplier.util.ScalableCardHelper;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class PhotoActivity extends AppCompatActivity {

    private int currentPostion = -1;
    private List<String> imageData = new ArrayList<>();
    private ViewPager viewPager;
    private TextView textView;
    private MyPagerAdapter pagerAdapter;
    RelativeLayout dialog_photo_rl;
    @BindView(R.id.dialog_photo_tv)
    TextView dialog_photo_tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo);
        ButterKnife.bind(this);
        ImmersionBar.with(this)
                .statusBarDarkFont(true, 0.2f)
                .init();

        currentPostion = getIntent().getIntExtra("currentPostion", 0);
//        imageData = getIntent().getStringArrayList("imageData");
        imageData = getIntent().getStringArrayListExtra("imageData");
        viewPager = (ViewPager) findViewById(R.id.dialog_photo_vp);
        textView = (TextView) findViewById(R.id.dialog_photo_tv);
        pagerAdapter = new MyPagerAdapter(this, imageData);
        viewPager.setAdapter(pagerAdapter);

        textView.setText(currentPostion + 1 + "/" + imageData.size());

        viewPager.setCurrentItem(currentPostion, false);
        initListener();
    }

    private void initListener() {
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                textView.setText(position + 1 + "/" + imageData.size());
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        pagerAdapter.setCallBack(new MyPagerAdapter.onCallBack() {
            @Override
            public void onItemClick() {
                finish();
            }
        });
    }

    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = new Dialog(this);
        if (dialog != null) {
            Window window = dialog.getWindow();
            if (window != null) {
                int width = ViewGroup.LayoutParams.MATCH_PARENT;
                int height = ViewGroup.LayoutParams.MATCH_PARENT;
                window.setLayout(width, height); // 使dialog充满真个屏幕
            }
        }
    }

    @OnClick({R.id.dialog_photo_tv,R.id.dialog_photo_vp})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.dialog_photo_tv:
                finish();
                break;
            case R.id.dialog_photo_vp:
                finish();
                break;
        }
    }


}




